//引入模块

$(function () {
    // 1.获取当前url中的路由名称
    var str = location.href
    var routername = '' // 路由名称
    // 1.1 判断是否有参数
    var index = str.indexOf('?')
    if (index != -1) { // 有参数
        routername = str.substring(str.lastIndexOf('/') + 1, index)
        console.log(routername)
    } else {
        routername = str.substring(str.lastIndexOf('/') + 1)
    }
    var menu_posts = $('#menu-posts')
    var menu_settings = $('#menu-settings')
    // 2.为对应的导航项设置属性和样式
    if (routername == 'post' || routername == 'categories' || routername == 'postadd') {
        menu_posts.addClass('in')
        menu_posts.attr('aria-expanded', true)
    } else if (routername == 'navmenus' || routername == 'sliders' || routername == 'settings') {
        menu_settings.addClass('in')
        menu_settings.attr('aria-expanded', true)
    }
    $('#' + routername).addClass('active')
    $('#' + routername).parent().siblings('a').removeClass('collapsed')
})